From ea07fa29e208fa822187b4beee0a41dd75aad50a Mon Sep 17 00:00:00 2001 From: "emellor@ewan" Date: Sun, 18 Sep 2005 18:18:52 +0100 Subject: [PATCH] Added allocateDeviceID, which uses the store to keep track of per-domain, per-device-class device IDs on behalf of the DevController subclasses. Signed-off-by: Ewan Mellor --- tools/python/xen/xend/server/DevController.py | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/tools/python/xen/xend/server/DevController.py b/tools/python/xen/xend/server/DevController.py index f315f0470b..f8fe749ffc 100644 --- a/tools/python/xen/xend/server/DevController.py +++ b/tools/python/xen/xend/server/DevController.py @@ -117,6 +117,31 @@ class DevController: return self.vm.getDomain() + def allocateDeviceID(self): + """Allocate a device ID, allocating them consecutively on a + per-domain, per-device-class basis, and using the store to record the + next available ID. + + This method is available to our subclasses, though it is not + compulsory to use it; subclasses may prefer to allocate IDs based upon + the device configuration instead. + """ + path = self.frontendMiscPath() + t = xstransact(path) + try: + result = t.read("nextDeviceID") + if result: + result = int(result) + else: + result = 1 + t.write("nextDeviceID", str(result + 1)) + t.commit() + return result + except: + t.abort() + raise + + ## private: def writeDetails(self, config, devid, backDetails, frontDetails): @@ -170,6 +195,9 @@ class DevController: def frontendPath(self, devid): - return "%s/device/%s/%d" % (self.vm.getPath(), - self.deviceClass, + return "%s/device/%s/%d" % (self.vm.getPath(), self.deviceClass, devid) + + + def frontendMiscPath(self): + return "%s/device-misc/%s" % (self.vm.getPath(), self.deviceClass) -- 2.30.2